//
//  RHNetworkHelpVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/9/27.
//

#import "RHNetworkHelpVC.h"
#import "RHNetworkHelpCell.h"
#import "SYChartTool.h"


@interface RHNetworkHelpVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataArr;
@end

@implementation RHNetworkHelpVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"配网常见问题".rh_localized;
    self.view.backgroundColor = CFTabViewBgColor;
    [self setupUI];
}

- (void)setupUI{
    
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"NetworkHelp" ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    self.dataArr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setBackgroundColor:CFTabViewBgColor];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView registerClass:[RHNetworkHelpCell class] forCellReuseIdentifier:@"RHNetworkHelpCell"];
    
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, kSafe_bottom, 0));
        
    }];
    
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
}




#pragma mark - UITableViewDelegate,UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return  [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 10)];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RHNetworkHelpCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHNetworkHelpCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    NSString *question = self.dataArr[indexPath.row][@"question"];
    NSString *answer = self.dataArr[indexPath.row][@"answer"];
    cell.QContentLab.text = question.rh_localized;
    cell.AContentLab.text = answer.rh_localized;
    return cell;
}
@end
